/**
 * @ToolTip.as.as
 * 
 * @author sodaChen mail:sujun10#21cn.com
 * @version 1.0
 * <br>Copyright (C), 2010 asFrame.com
 * <br>This program is protected by copyright laws.
 * <br>Program Name:FlyDragon
 * <br>Date:2014-2-15
 */
package com.asframe.display
{
	import flash.accessibility.*;
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.text.*;
	
	public class ToolTip extends Sprite
	{
		private var _txt:TextField;
		private var _area:DisplayObject;
		private const UP_COLOR:uint = 16777215;
		private const DOWN_COLOR:uint = 0;
		private const TEXT_COLOR:uint = 6710886;
		private static var _instance:ToolTip = null;
		private static var _info:String = "";
		
		public function ToolTip()
		{
			this._txt = new TextField();
			this._txt.autoSize = TextFieldAutoSize.LEFT;
			this._txt.selectable = false;
			this._txt.multiline = true;
			this._txt.wordWrap = false;
			this._txt.defaultTextFormat = new TextFormat("宋体", 14, this.TEXT_COLOR);
			this._txt.htmlText = "提示信息";
			this._txt.x = 8;
			this._txt.y = 5;
			addChild(this._txt);
			this.initDraw();
			visible = false;
			var _loc_1:* = false;
			mouseChildren = false;
			mouseEnabled = _loc_1;
			return;
		}// end function
		
		private function initDraw() : void
		{
			var _loc_1:* = 30 + this._txt.width;
			var _loc_2:* = 10 + this._txt.height;
			this.graphics.clear();
			this.graphics.beginFill(this.DOWN_COLOR, 0.4);
			this.graphics.drawRoundRect(0, 0, _loc_1 + 5, _loc_2 + 5, 5, 5);
			this.graphics.moveTo(int(_loc_1 / 2), 5 + _loc_2);
			this.graphics.lineTo(int(_loc_1 / 2) + 14, 5 + _loc_2);
			this.graphics.lineTo(int(_loc_1 / 2) + 7, 15 + _loc_2);
			this.graphics.lineTo(int(_loc_1 / 2), 5 + _loc_2);
			this.graphics.endFill();
			this.graphics.beginFill(this.UP_COLOR);
			this.graphics.drawRoundRect(3, 3, _loc_1, _loc_2, 5, 5);
			this.graphics.moveTo(int(_loc_1 / 2), 3 + _loc_2);
			this.graphics.lineTo(int(_loc_1 / 2) + 12, 3 + _loc_2);
			this.graphics.lineTo(int(_loc_1 / 2) + 6, 13 + _loc_2);
			this.graphics.lineTo(int(_loc_1 / 2), 3 + _loc_2);
			this.graphics.endFill();
			return;
		}// end function
		
		private function show(param1:DisplayObject) : void
		{
			this._area = param1;
			this._area.addEventListener(MouseEvent.MOUSE_OUT, this.handler);
			this._area.addEventListener(MouseEvent.MOUSE_MOVE, this.handler);
			this._txt.htmlText = param1.accessibilityProperties.description;
			this.initDraw();
			return;
		}// end function
		
		private function hide() : void
		{
			this._area.removeEventListener(MouseEvent.MOUSE_OUT, this.handler);
			this._area.removeEventListener(MouseEvent.MOUSE_MOVE, this.handler);
			this._area = null;
			visible = false;
			return;
		}// end function
		
		public function move(param1:Point) : void
		{
			var _loc_2:* = this.parent.globalToLocal(param1);
			this.x = _loc_2.x - (this._txt.width + 30) / 2;
			this.y = _loc_2.y - this._txt.height - 30 - this._area.height;
			if (!visible)
			{
				visible = true;
			}
			return;
		}// end function
		
		public function handler(event:MouseEvent) : void
		{
			switch(event.type)
			{
				case MouseEvent.MOUSE_OUT:
				{
					this.hide();
					break;
				}
				case MouseEvent.MOUSE_OVER:
				{
					this.show(event.currentTarget as DisplayObject);
					this.move(new Point(event.stageX, event.stageY));
					break;
				}
				case MouseEvent.MOUSE_MOVE:
				{
					this.move(new Point(event.stageX, event.stageY));
					break;
				}
				default:
				{
					break;
				}
			}
			return;
		}// end function
		
		public static function init(param1:DisplayObjectContainer) : void
		{
			if (_instance == null)
			{
				_instance = new ToolTip;
				param1.addChild(_instance);
			}
			return;
		}// end function
		
		public static function register(param1:DisplayObject, param2:String) : void
		{
			var _loc_3:* = null;
			if (_instance != null)
			{
				_loc_3 = new AccessibilityProperties();
				_loc_3.description = param2;
				param1.accessibilityProperties = _loc_3;
				param1.addEventListener(MouseEvent.MOUSE_OVER, _instance.handler);
			}
			return;
		}// end function
		
		public static function unregister(param1:DisplayObject) : void
		{
			if (_instance != null)
			{
				param1.removeEventListener(MouseEvent.MOUSE_OVER, _instance.handler);
			}
			return;
		}// end func
	}
}